﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace WindowsCommonStorage
{
    public abstract class CommonStorageItem
    {
        
        public string Path { get { return ErrorHandler.Func(() => { return ProtectedPath; }); } }
        internal protected abstract string ProtectedPath { get; }

        public string Name { get { return ErrorHandler.Func(() => { return ProtectedName; }); } }
        internal protected abstract string ProtectedName { get; }

        public CommonFileAttributes Attributes { get { return ErrorHandler.Func(() => { return ProtectedAttributes; }); } }
        internal protected abstract CommonFileAttributes ProtectedAttributes { get;}
        /// <summary>
        /// 現在のファイルが作成された日時を取得します
        /// </summary>
        public DateTimeOffset DateCreated { get { return ErrorHandler.Func(() => { return ProtectedDateCreated; }); } }
        internal protected abstract DateTimeOffset ProtectedDateCreated { get; }


        public async Task RenameAsync(string desiredName)
        {
            await ErrorHandler.AsyncAction(async () =>
            {
                await ProtectedRenameAsync(desiredName).ConfigureAwait(false);

            }).ConfigureAwait(false);
        }
        internal protected abstract Task ProtectedRenameAsync(string desiredName);

        public async Task RenameAsync(string desiredName, CommonNameCollisionOption option)
        {
            await ErrorHandler.AsyncAction(async () =>
            {
                await ProtectedRenameAsync(desiredName, option).ConfigureAwait(false);

            }).ConfigureAwait(false);
        }
        internal protected abstract Task ProtectedRenameAsync(string desiredName, CommonNameCollisionOption option);

        public async Task DeleteAsync()
        {
            await ErrorHandler.AsyncAction(async () =>
            {
                await ProtectedDeleteAsync().ConfigureAwait(false);

            }).ConfigureAwait(false);
        }
        internal protected abstract Task ProtectedDeleteAsync();


        public bool IsOfType(CommonStorageItemTypes itemType)
        {
            return ProtectedIsOfType(itemType);
        }

        internal protected abstract bool ProtectedIsOfType(CommonStorageItemTypes itemType);


    }
}
